/**
 * Copyright 厦门中软海晟信息技术有限公司 版权所有 违者必究 2019
 */
package com.leetCode;

import java.util.LinkedList;
import java.util.Queue;

/**
 * @author : sunzb(sunzb@hsit.com.cn)
 * @date: 2019/5/13
 */
public class _3_225_ImplementStackUsingQueues {

    private LinkedList<Integer> q1 = new LinkedList<>();

    private int top = 0;

    /** Push element x onto stack. */
    public void push(int x) {
            q1.add(x);
        int sz = q1.size();
        while (sz > 1) {
            q1.add(q1.remove());
            sz--;
        }
    }

    /** Removes the element on top of the stack and returns that element. */
    public int pop() {
        return q1.remove();
    }

    /** Get the top element. */
    public int top() {
        return q1.peek();
    }

    /** Returns whether the stack is empty. */
    public boolean empty() {
        return q1.isEmpty();
    }

    public static void main(String[] args) {
        _3_225_ImplementStackUsingQueues q = new _3_225_ImplementStackUsingQueues();
        q.push(1);
        q.push(2);
        q.push(3);
        System.out.println(q.top());
        System.out.println(q.pop());
        System.out.println(q.top());
        System.out.println(q.pop());
        System.out.println(q.top());
    }
}
